package edu.fafu.action;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.struts2.interceptor.RequestAware;
import org.apache.struts2.interceptor.SessionAware;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import edu.fafu.entity.Admin;
import edu.fafu.entity.User;
import edu.fafu.service.ILoginService;

@Controller
public class LoginAction extends ActionSupport implements SessionAware,RequestAware{
	@Resource(name="loginService")
	private ILoginService loginService;
	
	public String login() throws Exception {
		User u = loginService.findUser(user);
		session.put("user",u);
		return SUCCESS;
	}
	
	public String register() throws Exception {
		
		return SUCCESS;
	}
	
	public String addUser() throws Exception {
		loginService.addUser(user);
		session.put("msg","注册成功");
		return SUCCESS;
	}
	
	public String checkPassword(){
		User user1 = (User)session.get("user");
		if(user1.getPwd().equals(user.getPwd())){
			json.put("msg","yes");
		}else{
			json.put("msg","no");
		}		
		return SUCCESS;
	}

	public String updatePassword(){
		User user1 = (User)session.get("user");
		user1.setPwd(user.getPwd());
		loginService.updatePassword(user1);
		json.put("msg", "修改成功!");
		return SUCCESS;
	}
	private User user;
	private Map<String,Object> json = new HashMap<String, Object>();
	private Map<String,Object> session;
	private Map<String,Object> request;

	
	public Map<String, Object> getJson() {
		return json;
	}

	public void setJson(Map<String, Object> json) {
		this.json = json;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	@Override
	public void setSession(Map<String, Object> session) {
		// TODO Auto-generated method stub
		this.session = session;
	}

	@Override
	public void setRequest(Map<String, Object> request) {
		// TODO Auto-generated method stub
		this.request = request;
	}


}	
